All Questions
70 questions
6votes
7answers
1kviews
Filter non-even elements from an array
I have a method that returns an int[]. The array is made by filtering out only the even values of the array passed into the method. It works, but it's really ugly ...
2votes
1answer
85views
Implementing an improved merge sort that uses insertion sort, with "levels" - Would this work correctly?
We were asked to improve the merge sort algorithm by introducing insertion sort to the code. We have been tasked with doing this by utilising a "levels" logic. Here is the exact description ...
2votes
2answers
193views
Quick Sort Program
Quick sort is a sorting algorithm in which we select any random element as pivot from the array and we do the partition of the array around that pivot. Basically we place all the elements smaller than ...
4votes
1answer
947views
Writing a Java program that outputs a calorie/macronutrient plan for getting in shape over a certain amount of weeks
I am new to programming and was working on a project that calculates an entire "diet plan" as well as a projected weight goal for each week. There are three objects that all have methods ...
1vote
1answer
765views
Proper way to transform nested lists to nested maps [closed]
I want to transform a list of lists of lists that I have in a MongoDB document into a map of maps of maps in my java Domain class. The problem I have is that the fields are mixed between the levels. ...
0votes
1answer
981views
Find the minimal distance between two values in an array [closed]
Given 2 values and an array, I must return the minimal distance between the indices of both values, as efficiently as I can in terms of run time and space. This is my solution: ...
5votes
4answers
571views
Fastest function to find cumulative largest perfect squares of a single number?
I'm attempting to write an algorithm that will find the largest perfect squares of a given integer, subtracting their values from the total each time, as fast as possible. It's somewhat hard to ...
0votes
3answers
1kviews
Calculate square of (sum of even-indexed) - (sum of odd-indexed) subarrays from an array
Find all subarrays from a given array in the least possible time complexity. Requirement: calculate the square of (sum of even-indexed elements) - (the sum of odd-indexed elements) of al the subarrays....
1vote
2answers
202views
How to take out attribute from two ArrayList of object which have different match in optimize way
I have two ArrayLists of objects and the after comparison I am taking out the value which has a difference based on the attribute. So in my condition when the ...
5votes
3answers
552views
HackRank - Array Rotate Optimization
I am working on a basic Array rotate code for a Hacker Rank challenge. The code is complete and passes all test cases, except for 2 which it times out on. I was wondering if there is a way to make ...
3votes
1answer
96views
Java i/o speed less than python i/o while printing an array
Motivation: I was solving an array based i/o problem and encountered Time Limit Errors, it was later found that the code for java ran roughly 10x slower than the ...
2votes
1answer
70views
Molybdenum2019 challenge efficient implementation
I'm working on a solution that is correct but inefficient. https://app.codility.com/programmers/task/leader_slice_inc/ This is my code : ...
4votes
2answers
539views
Dynamic Array in java
I am implementing a class to mimic dynamic array as a part of my learning process of data structures. I have written the following class which works as a dynamic array data structure. I have gone ...
2votes
1answer
557views
Speeding up a recursive Cantor pairing function
The Cantor Pairing function is a mathematical function which takes two integers and combines them into a single integer that is unique to that pair. This single integer can later be "unpaired" back ...
4votes
5answers
1kviews
Counting number of `1` digits in the value of \$11^n\$
I am trying to improve the efficiency of my code, The Question is: Given a value n, where n is in the range ...